﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.IO;

/// <summary>
/// CFile 的摘要说明
/// </summary>
internal static class CFile
{
    /// <summary>
    /// 创建某路径下的所有文件夹,如: D:/webpart/0101 检查是否有该文件夹,没有则新建
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    public static bool CreateDirectory(string path)
    {
        if (!Directory.Exists(Directory.GetDirectoryRoot(path)))
        {
            return false;
        }

        try
        {
            Directory.CreateDirectory(path);
            return true;
        }
        catch
        {
            return false;
        }
    }

    /// <summary>
    /// 删除某目录,包括它下面的所有子目录
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    public static void DeleteDirectory(string path)
    {
        if (Directory.Exists(path)) //如果存在这个文件夹删除之   
        {
            foreach (string d in Directory.GetFileSystemEntries(path))
            {
                if (File.Exists(d))
                    File.Delete(d); //直接删除其中的文件                          
                else
                    DeleteDirectory(d); //递归删除子文件夹   
            }

            try
            {
                if (Directory.Exists(path))
                    Directory.Delete(path, true); //删除已空文件夹      
            }
            catch { }

        } 
    }    

}
